/*
 * InterfaceLoader.java
 *
 * Created on 22. April 2007, 19:51
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package de.tor.loaders;

import com.golden.gamedev.GameEngine;
import com.golden.gamedev.GameObject;
import com.golden.gamedev.object.Sprite;
import de.tor.obj.AbstractWeapon;
import de.tor.obj.impl.ProjectileFactory;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.image.BufferedImage;

/**
 *
 * @author Charon
 */
public class Interface extends GameObject{
    
    Sprite energy, shield, energyFill, shieldFill, scores, weapons;
    private final int X_OFFSET= 12;
    private final int Y_OFFSET= 10;
    private Level mLevel;
    private  Player mOwner = null;
    
    private int iPlayerHealth = 100;
    private int iPlayerShield = 100;
    
    /** Creates a new instance of InterfaceLoader */
    public Interface(GameEngine parent, Level level, Player pOwner) {
        super(parent);
        mLevel = level;
        mOwner = pOwner;
    }
    
    private void calculatePlayerStatus(){
        if(mOwner.getMaxShield() == 0){
            iPlayerShield = 0;
        }else{
            iPlayerShield = (int)(100 * mOwner.getShield() /  mOwner.getMaxShield());
        }
        iPlayerHealth = (int)(100 * mOwner.getHealth() /  mOwner.getMaxHealth());
    }
    
    public void initResources() {
        energy = new Sprite(getImage("resources/interface/energy.png"), 0, 0);
        shield = new Sprite(getImage("resources/interface/shield.png"), 0, 0);
        
        energyFill = new Sprite(getImage("resources/interface/energyFill.png"), 0, 0);
        shieldFill = new Sprite(getImage("resources/interface/shieldFill.png"), 0, 0);
        
        scores = new Sprite(getImage("resources/interface/scores.png"), 0, 0);
        weapons = new Sprite(getImage("resources/interface/weapons.png"), 0, 0);
    }
    
    public double getInterfaceHeight(){
        return energy.getHeight();
    }
    
    public void render(Graphics2D graphics2D) {
        graphics2D.setColor(Color.RED);
        calculatePlayerStatus();
        
        int healthFillPerc = (int)(67 * iPlayerHealth/100);
        graphics2D.fillRect(30 + 6, 768 - 100 + (67 - healthFillPerc), 18, healthFillPerc);
        graphics2D.setColor(Color.BLUE);
        
        int shieldFillPerc = (int)(67 * iPlayerShield/100);
        graphics2D.fillRect(1024 - 30 - 6 - 18, 768 - 100 + (67 - shieldFillPerc), 18, shieldFillPerc);
        graphics2D.drawImage(energy.getImage(), 30, 768 - energy.getHeight(), null);
        
        graphics2D.drawImage(shield.getImage(), 1024 - shield.getWidth() - 30, 768 - energy.getHeight(), null);
        graphics2D.drawImage(scores.getImage(), 1024 - scores.getWidth(), 0, null);
        graphics2D.drawImage(weapons.getImage(), 1024 / 2 - weapons.getWidth()/2,  768 - weapons.getHeight(), null);
        for(int slot = 0;slot < 6; slot++){
            BufferedImage slotImage = null;
            int xPos = 0;
            int yPos = 53;
            if(mOwner.getWeaponList().size() < slot+1){
                slotImage = ProjectileFactory.getSymbol(ProjectileFactory.NO_PROJECTILE);
                xPos = -1;
                yPos = 51;
            }else{
                slotImage = ProjectileFactory.getSymbol(mOwner.getWeaponList().get(slot).getProjectile());
            }

            switch(slot){
                case 1:{
                    xPos += 369;
                    break;
                }case 2:{
                    xPos += 333;
                    break;
                }case 3:{
                    xPos += 298;
                    break;
                }case 4:{
                    xPos += 265;
                    break;
                }case 5:{
                    xPos += 230;
                    break;
                }default:{
                    xPos += 403;
                    break;
                }
            }
            graphics2D.drawImage(slotImage, 1024 / 2 - weapons.getWidth()/2 + xPos, 768 - weapons.getHeight() + yPos, null);
        }
    }
    
    public void update(long l) {
    }
}
